/**
 * @overview 添加BIM和倾斜
 * @author dengqiang
 * @description 引用鲸云 Cgs3DTileset 类
 * @update  2022.03.21
 */
class G3DTileset {
  constructor() {
    window.G3DTilesetArray = []
  }

  add(paramObj) {
    const { name, parentName, option } = paramObj
    const optionModified = {
      url: option.url,
      proxy: false, // 使用默认jsp代理进行数据请求（仅支持java环境）
      shadow: 1, // 阴影模式(0为关闭，1为开启)
      showBounding: false, // 包围盒显示标识
      enableSelected: false, // 模型是否可被选中
      enableCallback: false, //开启回调
      selectColor: 'rgba(255,255,255,1)', // 选中颜色
      highlightColor: 'rgba(255,255,0,1)', // 高亮颜色
      baseColor: 'rgba(255,255,255,1)', // 模型基颜色
      maximumScreenSpaceError: window.app.config.globalProperties.$config.maximumScreenSpaceError,
      dynamicScreenSpaceError: true,
      maximumMemoryUsage: window.app.config.globalProperties.$config.maximumMemoryUsage,
      offsetHeight: option.offsetHeight || 0, //模型偏移高度
      positionNew: option.positionNew || undefined,
      locate: false,
    }
    const tileSet = new Cgs3DTileset(optionModified, map)

    // tileSet.feature3D.tileset.cullRequestsWhileMovingMultiplier = 10
    // tileSet.feature3D.tileset.loadSiblings = false
    // tileSet.feature3D.tileset.maximumMemoryUsage = 10000
    // tileSet.feature3D.tileset.progressiveResolutionHeightFraction = 0.5
    // tileSet.feature3D.tileset.dynamicScreenSpaceErrorDensity = 10
    // tileSet.feature3D.tileset.dynamicScreenSpaceErrorFactor = 1
    // tileSet.feature3D.tileset.dynamicScreenSpaceErrorHeightFalloff = 0.25
    // tileSet.feature3D.tileset.dynamicScreenSpaceError = true
    // tileSet.feature3D.tileset.skipLevels = 1
    // tileSet.feature3D.tileset.immediatelyLoadDesiredLevelOfDetail = false
    // tileSet.feature3D.tileset.cullWithChildrenBounds = false
    // tileSet.feature3D.tileset.cullRequestsWhileMoving = false
    // tileSet.feature3D.tileset.preloadWhenHidden = true
    // tileSet.feature3D.tileset.preloadFlightDestinations = true
    // tileSet.feature3D.tileset.preferLeaves = true
    // tileSet.feature3D.tileset.foveatedScreenSpaceError = true
    // tileSet.feature3D.tileset.foveatedConeSize = 0.1
    // tileSet.feature3D.tileset.foveatedMinimumScreenSpaceErrorRelaxation = 0.0

    const tileSetObject = {
      name: name,
      parentName: parentName,
      tileSet: tileSet,
    }
    window.map.addFeature(tileSet)
    window.G3DTilesetArray.push(tileSetObject)
    return tileSet
  }

  // removeSingleTileset(name) {
  // 	window.G3DTilesetArray.forEach((item, index) => {
  // 		if (item.name == name) {
  // 			window.G3DTilesetArray.splice(index, 1);
  // 			window.map.removeFeature(item.tileSet);
  // 		}
  // 	})
  // }

  // removeAll() {
  // 	window.G3DTilesetArray.forEach((item) => {
  // 		window.map.removeFeature(item.tileSet);
  // 	})
  // 	window.G3DTilesetArray = [];
  // }

  removeAllTilesetExclude(name) {
    window.G3DTilesetArray.forEach((item, index) => {
      if (item.name == name) {
      } else {
        window.G3DTilesetArray.splice(index, 1)
        window.map.removeFeature(item.tileSet)
      }
    })
  }

  // setVisible(name, boolean) {
  // 	window.G3DTilesetArray.forEach((item, index) => {
  // 		if (item.name == name) {
  // 			item.tileSet.setVisible(boolean);
  // 		}
  // 	})
  // }

  //根据name移除单个围墙
  removeByName(name) {
    window.G3DTilesetArray.forEach((item, index) => {
      if (item.name == name) {
        window.map.removeFeature(item.tileSet)
        window.G3DTilesetArray.splice(index, 1)
      }
    })
  }

  //根据parentName移除一批围墙
  removeByPatName(parentName) {
    const length = window.G3DTilesetArray.length
    for (let i = length - 1; i >= 0; i--) {
      if (window.G3DTilesetArray[i].parentName == parentName) {
        window.map.removeFeature(window.G3DTilesetArray[i].tileSet)
        window.G3DTilesetArray.splice(i, 1)
      }
    }
  }

  //移除所有围墙
  removeAll() {
    window.G3DTilesetArray.forEach((item) => {
      window.map.removeFeature(item.tileSet)
    })
    window.G3DTilesetArray = []
  }

  //根据name控制单个围墙的显隐
  setVisibleByName(name, boolean) {
    window.G3DTilesetArray.forEach((item) => {
      if (item.name == name) {
        item.tileSet.setVisible(boolean)
      }
    })
  }

  //根据parentName控制一批围墙的显隐
  setVisibleByPatName(parentName, boolean) {
    window.G3DTilesetArray.forEach((item) => {
      if (item.parentName == parentName) {
        item.tileSet.setVisible(boolean)
      }
    })
  }
}

export default G3DTileset
